package com.adong.web;

import com.adong.pojo.User;
import com.adong.service.impl.UserServiceImpl;
import com.adong.utils.JdbcUtils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;

/**
 * @author adong
 * 原来用来专门处理注册页面的验证
 * 现在和注册类都封装到userservlet中去了
 */
@Deprecated
public class LoginServlet extends HttpServlet {
    UserServiceImpl userServlet = new UserServiceImpl();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String userName = req.getParameter("username");
        String passWord = req.getParameter("password");
        //判断用户名和密码正确
        if (userServlet.loginUser(new User(null,userName, passWord, null)) == null) {
            //密码或者用户名没有找到
            req.setAttribute("message","用户名或者密码错误");
            req.setAttribute("username",userName);
            req.getRequestDispatcher("/pages/user/login.jsp").forward(req, resp);

        } else {
            //找到用户名和密码
            req.getRequestDispatcher("/pages/user/login_success.jsp").forward(req, resp);
        }



    }
}
